package com.hub.controller;

import com.hub.frame.service.security.IAuthService;
import com.hub.service.IAuthUserInfoService;
import com.hub.utils.ApiResultObject;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * LoginController
 *
 * @description: 登录Controller
 * @author hub
 * @create: 2020-05-13 17:10
 */
@RestController
@RequestMapping("/users")
public class LoginController {

    @Autowired
    private IAuthUserInfoService authUserInfoService;
    @Autowired
    private IAuthService authService;

    @ApiOperation("普通登录")
    @GetMapping("/login")
    public ApiResultObject login(@RequestParam(value = "username") String username,
                                 @RequestParam(value = "password") String password) throws Exception {
        return authUserInfoService.login(username, password);
    }

    @ApiOperation("获取用户信息")
    @PostMapping("/info")
    @RequiresAuthentication
    public ApiResultObject getUserInfo(){
        return authUserInfoService.loadMenuInfo();
    }

    @ApiOperation("退出登录")
    @PostMapping("logout")
    @RequiresAuthentication
    public ApiResultObject logout() {
        return authUserInfoService.logout();
    }

}
